"gallery filter"
Bootstrap 3.3.0 Snippet by Rajnesh Prajapati

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row" style=" margin:20px"> <div class="col-xs-12"> <button class="btn btn-small btn-danger" data-toggle="portfilter" data-target="all"> All </button> <button class="btn btn-small btn-danger" data-toggle="portfilter" data-target="art"> Websites </button> <button class="btn btn-small btn-danger" data-toggle="portfilter" data-target="media"> Brochures </button> <button class="btn btn-small btn-danger" data-toggle="portfilter" data-target="brand"> Logo design / Brand Collaterals </button> </div> </div> <div class="col-md-4" data-tag='brand'> <img src="http://placehold.it/450x250" class="img-responsive" alt="img"> </div> <div class="col-md-4" data-tag='media'> <img src="http://placehold.it/450x250" class="img-responsive" alt="img"> </div> <div class="col-md-4" data-tag='art'> <img src="http://placehold.it/450x250" class="img-responsive" alt="img"> </div> <div class="col-md-4" data-tag='art'> <img src="http://placehold.it/450x250" class="img-responsive" alt="img"> </div> <div class="col-md-4" data-tag='brand'> <img src="http://placehold.it/450x250" class="img-responsive" alt="img"> </div> <div class="col-md-4" data-tag='media'> <img src="http://placehold.it/450x250" class="img-responsive" alt="img"> </div> <div class="col-md-4" data-tag='media'> <img src="http://placehold.it/450x250" class="img-responsive" alt="img"> </div> <div class="col-md-4" data-tag='brand'> <img src="http://placehold.it/450x250" class="img-responsive" alt="img"> </div> </div>
/* ============================================================ * bootstrap-portfilter.js for Bootstrap v2.3.1 * https://github.com/geedmo/portfilter * ============================================================*/ !function(d){var c="portfilter";var b=function(e){this.$element=d(e);this.stuff=d("[data-tag]");this.target=this.$element.data("target")||""};b.prototype.filter=function(g){var e=[],f=this.target;this.stuff.fadeOut("fast").promise().done(function(){d(this).each(function(){if(d(this).data("tag")==f||f=="all"){e.push(this)}});d(e).show()})};var a=d.fn[c];d.fn[c]=function(e){return this.each(function(){var g=d(this),f=g.data(c);if(!f){g.data(c,(f=new b(this)))}if(e=="filter"){f.filter()}})};d.fn[c].defaults={};d.fn[c].Constructor=b;d.fn[c].noConflict=function(){d.fn[c]=a;return this};d(document).on("click.portfilter.data-api","[data-toggle^=portfilter]",function(f){d(this).portfilter("filter")})}(window.jQuery);

Related: See More


Questions / Comments:

Awesome snippet, I love it! I'm using it on a site I'm working on now to sort a gallery by tags. One thing though, it doesn't currently handle an item having more than one data-tag. i.e. in this example if you had an image that shows both a logo design AND a brochure, how do you make it appear when EITHER button is pressed? Anyone got ideas on how to tweak it?

Rachel Dunlop () - 7 years ago - Reply 0